package qc.module.demo.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.module.demo.dto.student.StudentAddDto;
import qc.module.demo.dto.student.StudentDto;
import qc.module.demo.dto.student.StudentQueryConditionDto;
import qc.module.demo.dto.student.StudentScoreDto;
import qc.module.demo.service.StudentService;

import java.util.List;

/**
 * StudentController
 */
@Api(tags = "学生-Student")
@RestController
@RequestMapping("/student")
public class StudentController {
    private StudentService studentService;

    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    /**
     * 查询学生信息
     *
     * @param condition 查询条件
     * @return 学生信息集合
     */
    @ApiOperation("查询-query")
    @RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
    public List<StudentDto> query(@RequestBody StudentQueryConditionDto condition) {
        return studentService.query(condition);
    }
    
    /**
     * 获取指定学生信息
     *
     * @param id 学号
     * @return 学生信息
     */
    @ApiOperation("获取指定-get")
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public StudentDto get(@RequestParam(value = "id", required = true) String id) {
        return studentService.get(id);
    }
    
    /**
     * 获取指定学生信息，从url中传值
     *
     * @param id 学号
     * @return 学生信息
     */
    @ApiOperation("获取指定-get")
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public StudentDto getByPath(@PathVariable(value = "id", required = true) String id) {
        return studentService.get(id);
    }
    
    /**
     * 新增学生信息
     *
     * @param studentAddDto 学生信息
     * @return 新增结果
     */

    @ApiOperation("新增-add")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody StudentAddDto studentAddDto) {
        return studentService.add(studentAddDto);
    }
    
    /**
     * 修改学生信息
     *
     * @param studentDto 学生信息
     * @return 修改结果
     */
    @ApiOperation("修改-update")
    @RequestMapping(value = "/update", method = {RequestMethod.PUT})
    public String update(@RequestBody StudentDto studentDto) {
        return studentService.update(studentDto);
    }
    
    /**
     * 删除学生信息
     *
     * @param id 学号
     * @return 删除结果
     */
    @ApiOperation("删除-delete")
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam(value = "id", required = true) String id) {
        return studentService.delete(id);
    }
    
    /**
     * 删除学生信息
     *
     * @param id 学号
     * @return 删除结果
     */
    @ApiOperation("删除-delete")
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable(value = "id", required = true) String id) {
        return studentService.delete(id);
    }
    
    /**
     * 获取学生成绩信息
     *
     * @param id 学号
     * @return 学生成绩列表
     */
    @ApiOperation("获取学生成绩-score")
    @RequestMapping(value = "/score", method = {RequestMethod.GET})
    public List<StudentScoreDto> getScores(@RequestParam(value = "id", required = false) String id) {
        return studentService.getScores(id);
    }
    /**
     * 获取学生成绩信息
     *
     * @param id 学号
     * @return 学生成绩列表
     */
    @ApiOperation("获取学生成绩-score")
    @RequestMapping(value = "/score/{id}", method = {RequestMethod.GET})
    public List<StudentScoreDto> getScoresByPath(@PathVariable(value = "id", required = false) String id) {
        return studentService.getScores(id);
    }
}
